<%--
  Created by IntelliJ IDEA.
  User: 27716
  Date: 2024/10/29
  Time: 14:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加</title>
    <script src="../../static/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../../static/css/css.css">
    <script>
        //文档就绪函数，获取动态下拉框
        $(function (){
            getGoodsType();
            getSupplier();
        })
        //商品类型 查询所有数据
        function getGoodsType(){
            $.ajax({
                url:"/goodsType/goodsType",
                dataType:"json",
                success(res){
                    console.log(res);
                    for (let o of res) {
                        //追加数据
                        $("#goodsTypeId").append(`
                            <option value="\${o.goodsTypeId}">\${o.goodsTypeName}</option>
                    `)
                    }
                },
                error(){
                    alert("服务器故障")
                }
            })

        }
        function getSupplier(){
            $.ajax({
                url:"/supplier/getSupplier",
                dataType: "json",
                success(res) {
                    for (let o of res) {
                        $("#supplierId").append(`
                            <option value="\${o.supplierId}">\${o.supplierName}</option>
                        `)
                    }
                },
                error() {
                    alert("服务器出现问题")
                }
            })
        }
        //供应商
    </script>
</head>
<body>
商品编码： <input type="text" id="goodsCode"> <br>
商品名称： <input type="text" id="goodsName"> <br>
库存数量： <input type="text" id="inventoryQuantity"> <br>
商品类型：<select id="goodsTypeId">
    <option value="">请选择</option>
</select> <br>
供应商名称： <select  id="supplierId">
    <option value="">请选择</option>
</select>
<input type="button" value="添加" onclick="getGoodsAdd()">
</body>
<script>
    function getGoodsAdd(){
        let goodsCode = $("#goodsCode").val();
        let goodsName = $("#goodsName").val();
        let inventoryQuantity = $("#inventoryQuantity").val();
        let goodsTypeId = $("#goodsTypeId").val();
        let supplierId = $("#supplierId").val();
        let obj = {goodsCode:goodsCode,goodsName:goodsName,inventoryQuantity:inventoryQuantity,goodsTypeId:goodsTypeId,supplierId:supplierId};
        $.ajax({
            url:"/goods/getGoodsAdd",
            type:"post",
            data:{reqInfos:JSON.stringify(obj)},
            dataType:"json",
            success(res){
                console.log(res);
                if(res === 200){
                    alert("添加成功");
                    location.href = "list.jsp";
                }
            },
            error(){
                alert("服务器出现问题")
            }
        })
    }
</script>
</html>
